cc.Class({
    extends: cc.Component,

    properties: {
        reveseTime :require('ReveseTime'),
        power : cc.Label,
        coin:cc.Label,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        // this.userInfo.setOptions(global.Data);
        this.updatePower(0);

        this.schedule(function () {
            var coinNumber=global.Data.goldCoin;
            this.coin.string = global.Common.getKV(coinNumber)
            this.power.string=global.Data.store.power
        }.bind(this), 1)
        
    },
    start(){
        this.coin.string = global.Common.getKV(global.Data.goldCoin)
    },

    updatePower(add){
        if(add){
            global.Data.store.leftRefreshTimeTick=global.Data.store.refreshTime
        }
        this.reveseTime.node.active = global.Data.store.power < global.Data.store.maxPower;
        if(global.Data.store.power < global.Data.store.maxPower){
            this.reveseTime.startRevese(global.Data.store.leftRefreshTimeTick/1000,()=>{
                global.Data.store.power++
                this.updatePower(1)
            })
        }
        this.power.string=global.Data.store.power
    },
});
